package servlet;

import dao.GoodsDao;
import dao.TypeDao;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/deleteType")
public class GoodsTypePrepareDeleteServlet extends HttpServlet {
	@Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) 
            throws ServletException, IOException {
        doGet(request, response);
    }
	@Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) 
            throws ServletException, IOException {
		request.setCharacterEncoding("utf-8");
		response.setCharacterEncoding("utf-8");
		
		Integer id = Integer.parseInt(request.getParameter("id"));
		TypeDao dao = new TypeDao();
		int ret = dao.deleteType(id);
		if(ret == -1) {
			response.sendRedirect("error.jsp");
			return;
		}else {
			request.getSession().setAttribute("successMsg", "删除成功！");
			request.getRequestDispatcher("./typeList").forward(request, response);
		}
	}
}
